package cn.appcentre.controller;


import cn.appcentre.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * method = RequestMethod.GET 可以限制请求，只处理post，或get
 */
@Controller     //扫描
@RequestMapping("user")
public class UserController {
//    @RequestMapping(value = "/testuser",method = RequestMethod.GET)
    @RequestMapping(value = "/testuser")
    @ResponseBody     //返回体是用spring-mvc.xml中的配置来处理
    //返回json测试
    public User testUser(){
        //直接返回json
        User user=new User();
        user.setId(23);
        user.setName("小明");
        return user;
    }
    //接受json测试,前台的json,封装到user中
    //测试时使用google插件postman
    @RequestMapping("/demouser")
    @ResponseBody
    public String  demoUser(@RequestBody User user){
        System.out.println("demouser接受到的json中"+user.getId()+";名称"+user.getName());

        return "demoUser";
    }
}
